﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace HECore.Tenant.Repository.Migrations
{
    public partial class Init : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "EmoloyeeRole",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "主键ID"),
                    EmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "员工Id"),
                    RoleId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "角色Id"),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "租户ID"),
                    CreatorEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "创建员工"),
                    CreationTime = table.Column<DateTime>(type: "datetime", nullable: false, comment: "创建时间"),
                    ModifiedEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true, comment: "最后修改员工"),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, comment: "最后修改时间"),
                    IsDelete = table.Column<bool>(type: "bit", nullable: false, comment: "是否逻辑删除"),
                    DeleterEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true, comment: "删除员工"),
                    DeletionTime = table.Column<DateTime>(type: "datetime", nullable: true, comment: "删除时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EmoloyeeRole", x => x.Id);
                },
                comment: "员工角色表");

            migrationBuilder.CreateTable(
                name: "Employee",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "员工Id"),
                    AccountId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "账号Id"),
                    EmployeeFullName = table.Column<string>(type: "nvarchar(55)", maxLength: 55, nullable: false, comment: "员工姓名"),
                    EmployeeEmail = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: true, comment: "员工邮箱"),
                    EmployeeState = table.Column<int>(type: "int", nullable: false, comment: "员工状态"),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "租户ID"),
                    CreatorEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "创建员工"),
                    CreationTime = table.Column<DateTime>(type: "datetime", nullable: false, comment: "创建时间"),
                    ModifiedEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true, comment: "最后修改员工"),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, comment: "最后修改时间"),
                    IsDelete = table.Column<bool>(type: "bit", nullable: false, comment: "是否逻辑删除"),
                    DeleterEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true, comment: "删除员工"),
                    DeletionTime = table.Column<DateTime>(type: "datetime", nullable: true, comment: "删除时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Employee", x => x.Id);
                },
                comment: "员工表");

            migrationBuilder.CreateTable(
                name: "EmployeeToken",
                columns: table => new
                {
                    IP = table.Column<string>(type: "nvarchar(128)", maxLength: 128, nullable: true, comment: "IP地址"),
                    Token = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "令牌"),
                    TokenExpireTime = table.Column<DateTime>(type: "datetime", nullable: false, comment: "令牌过期时间"),
                    RefreshToken = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "刷新令牌"),
                    RefreshTokenExpireTime = table.Column<DateTime>(type: "datetime", nullable: false, comment: "刷新令牌过期时间"),
                    RefreshCount = table.Column<int>(type: "int", nullable: false, comment: "刷新Token计数"),
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "租户ID"),
                    CreatorEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "创建员工"),
                    CreationTime = table.Column<DateTime>(type: "datetime", nullable: false, comment: "创建时间"),
                    ModifiedEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true, comment: "最后修改员工"),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, comment: "最后修改时间"),
                    IsDelete = table.Column<bool>(type: "bit", nullable: false, comment: "是否逻辑删除"),
                    DeleterEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true, comment: "删除员工"),
                    DeletionTime = table.Column<DateTime>(type: "datetime", nullable: true, comment: "删除时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EmployeeToken", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "Role",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "租户ID"),
                    RoleName = table.Column<string>(type: "nvarchar(55)", maxLength: 55, nullable: false, comment: "角色名称"),
                    RoleDescribe = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true, comment: "角色描述"),
                    IsSystemRole = table.Column<bool>(type: "bit", nullable: true, comment: "是否是系统角色"),
                    SystemRoleType = table.Column<int>(type: "int", nullable: true, comment: "系统角色类型"),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "租户ID"),
                    CreatorEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "创建员工"),
                    CreationTime = table.Column<DateTime>(type: "datetime", nullable: false, comment: "创建时间"),
                    ModifiedEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true, comment: "最后修改员工"),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, comment: "最后修改时间"),
                    IsDelete = table.Column<bool>(type: "bit", nullable: false, comment: "是否逻辑删除"),
                    DeleterEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true, comment: "删除员工"),
                    DeletionTime = table.Column<DateTime>(type: "datetime", nullable: true, comment: "删除时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Role", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "RolePermission",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "主键"),
                    TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "租户Id"),
                    RoleId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "角色Id"),
                    FunctionName = table.Column<string>(type: "nvarchar(max)", nullable: false, comment: "功能名称")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_RolePermission", x => x.Id);
                },
                comment: "角色拥有功能表");

            migrationBuilder.CreateTable(
                name: "Tenant",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "租户ID"),
                    Name = table.Column<string>(type: "nvarchar(55)", maxLength: 55, nullable: false, comment: "租户名称"),
                    Logo = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: true, comment: "租户Logo"),
                    CreatorEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: false, comment: "创建员工"),
                    CreationTime = table.Column<DateTime>(type: "datetime", nullable: false, comment: "创建时间"),
                    ModifiedEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true, comment: "最后修改员工"),
                    ModifiedTime = table.Column<DateTime>(type: "datetime", nullable: true, comment: "最后修改时间"),
                    IsDelete = table.Column<bool>(type: "bit", nullable: false, comment: "是否逻辑删除"),
                    DeleterEmployeeId = table.Column<Guid>(type: "uniqueidentifier", nullable: true, comment: "删除员工"),
                    DeletionTime = table.Column<DateTime>(type: "datetime", nullable: true, comment: "删除时间")
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Tenant", x => x.Id);
                },
                comment: "租户表");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "EmoloyeeRole");

            migrationBuilder.DropTable(
                name: "Employee");

            migrationBuilder.DropTable(
                name: "EmployeeToken");

            migrationBuilder.DropTable(
                name: "Role");

            migrationBuilder.DropTable(
                name: "RolePermission");

            migrationBuilder.DropTable(
                name: "Tenant");
        }
    }
}
